/* implement a stack data structure with linked list*/

var Node = require('./node');

class Stack {
    constructor() {
        this._first = null;
        this._count = 0;
    }

    isEmpty() {
        return this._count === 0;
    }

    size() {
        return this._count;
    }

    push(item) {
        if (item === 'undefined') {
            throw Error("No arguments");
        }
        let oldFirst = this._first;
        this._first = new Node();
        this._first.value = item;
        this._first.next = oldFirst;
        this._count++;
    }

    pop() {
        if (this._count <= 0) {
            throw Error('Empty Stack');
        }
        let item = this._first.value;
        this._first = this._first.next;
        this._count--;
        return item;
    }
}

module.exports = Stack;